﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers
{
    [RouteArea("admin")]
    [RoutePrefix("merchantBankCard")]
    public class MerchantBankCardController : AdminController
    {
        private IMerchantBankCardService _iMerchantBankCardService;

        public MerchantBankCardController(IMerchantBankCardService iMerchantBankCardService)
        {
            _iMerchantBankCardService = iMerchantBankCardService;
        }

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult Gets(MerchantBankCardQuery query)
        {
            var model = _iMerchantBankCardService.GetBankCards(query);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        public JsonResult Get(long id)
        {
            merchant_bank_card_dto_ex model = new merchant_bank_card_dto_ex() { status = EMerchantBankCardStatus.ToAudit };
            if (id > 0)
                model = _iMerchantBankCardService.GetBankCard(id);
            model.status_value = ((int)model.status).ToString();//ng-select 需要绑定字符串类型
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [ValidateInput(false)]
        public JsonResult Update(merchant_bank_card_dto_ex dto)
        {
            dto.status = (EMerchantBankCardStatus)int.Parse(dto.status_value);
            var result = _iMerchantBankCardService.AuditBankCard(dto, currentUser.user_id);
            return Json(ResultToJson.Json(result ? " 保存成功" : "未做任何修改", result), JsonRequestBehavior.AllowGet);

        }
    }
}